<template>
  <div :class="{ show: y >= 78 }" class="app-header-sticky">
    <div v-show="y > 78" class="container">
      <router-link class="logo" to="/"></router-link>
      <AppHeaderNav></AppHeaderNav>
      <div class="right">
        <router-link to="/">品牌</router-link>
        <router-link to="/">专题</router-link>
      </div>
    </div>
  </div>
</template>

<script>
import AppHeaderNav from '@/components/header/AppHeaderNav'
import { onMounted, ref } from 'vue'
import { useWindowScroll } from '@vueuse/core'

export default {
  name: 'AppHeaderSticky',
  components: {
    AppHeaderNav,

  },
  setup() {
    // // 记录y轴卷去的高度
    // const y = ref(0)
    // // 当你页面滚动的时候更新它, 实现效果: 当页面滚动到78px完成显示效果, 需要滑出动画
    // onMounted(() => {
    //   window.addEventListener('scroll', () => {
    //     y.value = window.scrollY
    //     console.log(y.value)
    //   })
    // })

    // 使用@vueuse/core工具库, 快速获取当前页面滚动时卷去的距离, 且是一个响应式的数据
    const { y } = useWindowScroll()
    return {
      y
    }
  }
}
</script>

<style lang="less" scoped>

.app-header-sticky {
  width: 100%;
  height: 80px;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 999;
  background-color: #fff;
  border-bottom: 1px solid #e4e4e4;
  // 默认移除顶部(向上偏移自身100%高度), 且完全透明 == display: none
  transform: translateY(-100%);
  opacity: 0;

  &.show {
    // 过度效果
    transition: all 0.3s linear;
    transform: none;
    opacity: 1;
  }

  .container {
    display: flex;
    align-items: center;

    .logo {
      width: 200px;
      height: 80px;
      background: url("../../assets/images/logo.png") no-repeat right 2px;
      background-size: 160px auto;
    }

    .right {
      width: 220px;
      display: flex;
      padding-left: 40px;
      border-left: 2px solid @xtxColor;
      text-align: center;

      a {
        width: 38px;
        margin-right: 40px;
        font-size: 16px;
        line-height: 1;

        &:hover {
          color: @xtxColor;
        }
      }
    }
  }
}


</style>
